﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace GUI_Test
{
    public partial class SubFormOracleConnection : Form
    {
        public SubFormOracleConnection()
        {
            InitializeComponent();

            textBoxOracleDBName.Text = "1521";
            textBoxOracleServerName.Text = "taurus.ccec.unf.edu";
            textBoxOracleServiceId.Text = "gporcl";
            textBoxOracleUserId.Text = "kaddou01";
            textBoxOraclePassword.Text = "n69880";
        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            if (!validateUserInput())
            {
                return;
            }

        }


        private bool validateUserInput()
        {
            bool isValid = true;
            if (textBoxOracleServerName.Text.Trim() == string.Empty || textBoxOracleDBName.Text.Trim() == string.Empty
                || textBoxOracleServiceId.Text.Trim() == string.Empty || textBoxOracleUserId.Text.Trim() == string.Empty
                || textBoxOraclePassword.Text.Trim() == string.Empty)
            {
                MessageBox.Show("Please fill all required fields.", "Error: Invalid Entry");
                isValid = false;
            }
            //if (textBoxOracleDBName.Text.Trim() == string.Empty)
            //{
            //    MessageBox.Show("Database name is required.", "Error: Invalid Entry");
            //    isValid = false;
            //}
            //if (textBoxOracleServiceId.Text.Trim() == string.Empty)
            //{
            //    MessageBox.Show("Service ID is required.", "Error: Invalid Entry");
            //    isValid = false;
            //}
            //if (textBoxOracleUserId.Text.Trim() == string.Empty)
            //{
            //    MessageBox.Show("User ID is required.", "Error: Invalid Entry");
            //    isValid = false;
            //}
            //if (textBoxOraclePassword.Text.Trim() == string.Empty)
            //{
            //    MessageBox.Show("Password is required.", "Error: Invalid Entry");
            //    isValid = false;
            //}
            return isValid;
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void SubFormOracleConnection_Load(object sender, EventArgs e)
        {
           
        }

        private void btnTestConnection_Click(object sender, EventArgs e)
        {

            try
            {
                SHARED.Oracle o = new SHARED.Oracle(textBoxOracleServerName.Text, int.Parse(textBoxOracleDBName.Text), textBoxOracleServiceId.Text,
                   textBoxOracleUserId.Text, textBoxOraclePassword.Text);

                if (o.isConnected())
                {
                    MessageBox.Show("successful");
                    return;
                }
                MessageBox.Show("failed");
            }
            catch
            {
                throw;
            }

        }
    }
}
